<template>
  <div class="summary-outline-wrap">
    <div class="summary-outline-btn">
      <div class="outline-btn-edit">
        <span v-show="!isEdit" class="mr20" @click="editHandler">编辑</span>
        <p class="mr20" v-show="isEdit">
          <span class="mr20" @click="saveHandler">保存</span>
          <span @click="cancelHandler">取消</span>
        </p>
      </div>
      <span class="export-btn" v-pdf="{ el: 'item-detail-p6', title: '阶段记录' }">导出</span>
      <!-- <div class="print" v-print="{ el: `#gf`, popTitle: '定制信息' }">打印</div> -->
    </div>
    <div class="item-detail-p6">
      <div class="summary-outline-title">阶段记录</div>
      <div id="gf">
        <div class="summary-outline-content">
          <div class="outline-info">
            <div class="outline-info-title">阶段信息记录</div>
            <el-input
              type="textarea"
              :disabled="!isEdit"
              :rows="18"
              :placeholder="isEdit ? '请填写' : ''"
              :autosize="true"
              v-model="taskOrigin.remark"
            ></el-input>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { ElMessage } from "element-plus";
import mittBus from "@/utils/mittBus";
import { getTaskDetail, updateProjectTask } from "@/api/modules/project"; // getProjectProblemAddList, deleteProjectProduct,
// 变量
const props = defineProps({
  detail: {
    type: Object,
    default: () => {}
  },
  task: {
    type: Object,
    default: () => {}
  }
});
const isEdit = ref(false);
let taskOrigin = ref({});

// 方法
const init = () => {
  taskOrigin.value = JSON.parse(JSON.stringify(props.task));
};
const editHandler = () => {
  isEdit.value = true;
};
const cancelHandler = () => {
  init();
  isEdit.value = false;
};
const saveHandler = async () => {
  try {
    isEdit.value = false;
    await updateProjectTask(taskOrigin.value);
    mittBus.emit("ProjectFileTime");
    refresh();
    ElMessage.success("保存成功");
  } catch (e) {
    console.log(e);
  }
};
const getTaskDetailFn = async () => {
  const { data } = await getTaskDetail({ id: props.task.id });
  taskOrigin.value = data;
};
const refresh = () => {
  getTaskDetailFn();
  // mittBus.emit("ProjectDetailRefresh");
};

onMounted(() => {
  refresh();
});
</script>
<style lang="scss" scoped>
.summary-outline-wrap {
  box-sizing: border-box;
  min-height: 100%;
  padding: 20px;
  background: #ffffff;
  p {
    margin: 0;
  }
  i {
    font-style: normal;
  }
  .mr20 {
    margin-right: 20px;
  }
  .mt10 {
    margin-top: 10px;
  }
  .summary-outline-btn {
    display: flex;
    justify-content: flex-end;
    font-size: 16px;
    font-weight: 400;
    color: var(--el-color-primary);
    .outline-btn-edit {
      display: flex;
      span {
        cursor: pointer;
      }
    }
  }
  .summary-outline-title {
    margin-top: 12px;
    margin-bottom: 60px;
    font-size: 26px;
    font-weight: 600;
    color: #333333;
    text-align: center;
  }
  .summary-outline-content {
    margin: 0 $project-padding;
  }
  .outline-info {
    ul,
    li {
      padding: 0;
      margin: 0;
      list-style: none;
    }
    &-title {
      margin-bottom: 20px;
      font-size: 16px;
      font-weight: 600;
      color: #333333;
    }
    &-list {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      column-gap: 10px;
      margin-bottom: 10px !important;
      li {
        display: flex;
        align-items: center;
        font-size: 14px;
        font-weight: 400;
        span:first-child {
          margin-right: 10px;
          color: #666666;
        }
        span:last-child {
          color: #333333;
        }
      }
      .info-width {
        width: 109px;
        text-align: right;
      }
    }
    :deep(.el-input),
    :deep(.el-textarea) {
      .el-input__wrapper {
        cursor: default;
        background: $project-background;
        box-shadow: none;
        .el-input__inner {
          cursor: default;
        }
      }
      .el-textarea__inner {
        min-height: 350px !important;
        cursor: default;
        resize: none;
        background: $project-background;
        box-shadow: none;
      }
    }
    :deep(.custom-title-edit) {
      .el-input__wrapper {
        cursor: default;
        background-color: #ffffff;
        box-shadow: none;
        .el-input__inner {
          cursor: default;
        }
      }
      .el-textarea__inner {
        cursor: default;
        background-color: #ffffff;
        box-shadow: none;
      }
    }
  }
}
</style>
